#Written by: Pericles Alves [periclesrafael@dcc.ufmg.br]

import numpy
import sys
import re

#extracts the results of the original version
original_file_name = sys.argv[1]
original_file = open(original_file_name, "r")
original_file_str = original_file.read()

original_file.close()

time_pattern = re.compile( r"runtime = (.+?) ms", re.DOTALL )

original_times = time_pattern.findall(original_file_str)

for i in range(0, len(original_times)):
    original_times[i] = float(original_times[i])

original_average = sum(original_times) / len(original_times)

#extracts the result of the optimized version
opt_file_name = sys.argv[2]
opt_file = open(opt_file_name, "r")
opt_file_str = opt_file.read()

opt_file.close()

opt_times = time_pattern.findall(opt_file_str)

for i in range(0, len(opt_times)):
    opt_times[i] = float(opt_times[i])

opt_average = sum(opt_times) / len(opt_times)

#prints the results
test_file = sys.argv[3]

print('"' + test_file + '" ' + str(1 - (opt_average / original_average)))
